@extends('shop::layouts.master')
@section('title')
    编辑权益
@endsection
@section('tab')
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" >
                    {{csrf_field()}}
                    <div class="layui-form-item">
                        <label for="L_alias" class="layui-form-label">
                            <span class="x-red">*</span>图片</label>
                        <div class="layui-input-inline">
                            <img class="layui-upload-img upload_img" src="admin/images/bg.png" height="100" width="150">
                            <input type="hidden" name="img" value="" lay-verify="pic_log" id="img_url">
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>活动名称</label>
                        <div class="layui-input-inline" style="width: 300px;">
                            <input type="text" name="title" lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入名称"></div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>活动类型</label>
                        <div class="layui-input-block" style="width: 300px;">
                        <select lay-filter="activity_type" name="type">
                            <option value="">请选择活动类型</option>
                            <option value="1">满减</option>
                            <option value="2">促销</option>
                        </select>
                        </div>
                    </div>

                    <div class="layui-form-item x-city " id="decrease" hidden="">
                        <div>
                            <div class="layui-inline" style="  z-index: 2;">
                                <label class="layui-form-label">满</label>
                                <div class="layui-input-block">
                                    <input type="tel" name="price_all[]" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline" style="margin-left: -90px;">
                                <label class="layui-form-label">减</label>
                                <div class="layui-input-block">
                                    <input type="text" name="price[]" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <button class="layui-btn" style="margin-top: -15px;" id="add_decrease">添加</button>
                        </div>
                    </div>

                    <div class="layui-form-item x-city " id="discount" hidden="">
                        <div>
                            <div class="layui-inline" style="  z-index: 2;">
                                <label class="layui-form-label">满</label>
                                <div class="layui-input-block">
                                    <input type="tel" name="price_all[]" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline" style="margin-left: -80px;">
                                <label class="layui-form-label">打折</label>
                                <div class="layui-input-block">
                                    <input type="text" name="price[]" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <button class="layui-btn" style="margin-top: -15px;" id="add_discount">添加</button>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>活动公告</label>
                        <div class="layui-input-block" style="width: 300px;">
                            <textarea name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red">*</span>活动时间
                        </label>
                        <div class="layui-input-block" style="width: 300px;">
                            <input type="text" class="layui-input" lay-verify="required" name="times" id="test16" placeholder="开始 到 结束" >
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="btn_edit" lay-submit="">确认</button>
                    </div>
                </form>
            </div>
        </div>

@endsection

@section('tab_js')
@include('shop::activity._js')
    <script>

        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            var is_submit = false;
            //监听提交
            form.on('submit(btn_edit)', function (data) {
                if( is_submit ){
                    return false;
                }
                is_submit = true;
                if( !data.field.img){
                    layer.msg("请上传banner图片", {time: 1000, icon: 5}); return false;
                }
                $.ajax({
                    url: js_url('shop-activity-store'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg("增加成功", {time: 500, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
                return false;

            });


        });
    </script>
@endsection